package io.renren.modules.course.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.course.entity.CourseSmallClassification;
import io.renren.modules.course.service.CourseSmallService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.course.entity.ClassificationEntity;
import io.renren.modules.course.service.ClassificationService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 技术类别列表
 *
 * @author zlb
 * @email 316682546@qq.com
 * @date 2018-07-04 09:29:28
 */
@RestController
@RequestMapping("course/classification")
public class ClassificationController {
    @Autowired
    private ClassificationService classificationService;

    @Autowired
    private CourseSmallService courseSmallService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("course:classification:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = classificationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("course:classification:info")
    public R info(@PathVariable("id") Integer id){
        ClassificationEntity classification = classificationService.selectById(id);

        return R.ok().put("classification", classification);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("course:classification:save")
    public R save(@RequestBody ClassificationEntity classification){
        classificationService.insert(classification);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("course:classification:update")
    public R update(@RequestBody ClassificationEntity classification){
        ValidatorUtils.validateEntity(classification);
        classificationService.updateAllColumnById(classification);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("course:classification:delete")
    public R delete(@RequestParam Integer id){
        classificationService.deleteById(id);

        return R.ok();
    }


  /*  *//**
     * 递归获取微课分类
     * @param id
     * @return
     *//*
    @GetMapping("getCourseSmallClassification")
    public R getCourseSmallClassification(@RequestParam int id){
        List<CourseSmallClassification> list =  courseSmallService.getCourseSmallClassification(id);

        return R.ok().put("data",list);
    }*/


   /* *//**
     * 模糊查询微课程
     *//*
    @GetMapping("getCourseSmallClassificationByTitleLike")
    public R getCourseSmallClassificationByTitleLike(@RequestParam String word){


        return R.ok();
    }*/

}
